package com.netty.chapter01.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author zjiajia
 * @date 2024/7/8 11:00
 */
public class NettyClient {
    public static void main(String[] args) throws InterruptedException {
        //
        NioEventLoopGroup workerGroup = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        // 设置启动类的属性
        bootstrap
                // 指定线程模型
                .group(workerGroup)
                // 指定 IO 类型为： NIO
                .channel(NioSocketChannel.class)
                // IO 的逻辑处理
                .handler(new ChannelInitializer<SocketChannel>() {
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        // 自定义的业务逻辑处理
                        socketChannel.pipeline().addLast(new NettyClientHandler());
                    }
                });
        // 建立连接
        ChannelFuture channelFuture = bootstrap.connect("127.0.0.1", 8888).sync();
    }
}
